package com.tigerlee.candle.ui;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tigerlee.candle.R;

public class CustomFrameOverlayView extends FrameLayout {

        private LinearLayout layout;
        private TextView title;
        private TextView name;
        private TextView snippet;

        /**
         * Create a new BalloonOverlayView.
         * 
         * @param context - The activity context.
         * @param balloonBottomOffset - The bottom padding (in pixels) to be applied
         * when rendering this view.
         */
        public CustomFrameOverlayView(Context context, int balloonBottomOffset) {

                super(context);

                setPadding(10, 0, 10, balloonBottomOffset);
                layout = new LinearLayout(context);
                layout.setVisibility(VISIBLE);

                LayoutInflater inflater = (LayoutInflater) context
                                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View v = inflater.inflate(R.layout.custom_mapframe, layout);
                title = (TextView) v.findViewById(R.id.mapframe_item_title);
                name = (TextView) v.findViewById(R.id.mapframe_item_name);
                snippet = (TextView) v.findViewById(R.id.mapframe_item_snippet);

                ImageView close = (ImageView) v.findViewById(R.id.close_img_button);
                close.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                                layout.setVisibility(GONE);
                        }
                });

                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                params.gravity = Gravity.NO_GRAVITY;

                addView(layout, params);

        }
        
        /**
         * Sets the view data from a given overlay item.
         * 
         * @param item - The overlay item containing the relevant view data 
         * (title and snippet). 
         */
        public void setData(CustomOverlayItem item) {
                
                layout.setVisibility(VISIBLE);
                if (item.getTitle() != null) {
                        title.setVisibility(VISIBLE);
                        title.setText(item.getTitle());
                } else {
                        title.setVisibility(GONE);
                }
                if (item.getName() != null) {
                	name.setVisibility(VISIBLE);
                	name.setText(item.getName());
                } else {
                	name.setVisibility(GONE);
                }
                if (item.getSnippet() != null) {
                        snippet.setVisibility(VISIBLE);
                        snippet.setText(item.getSnippet());
                } else {
                        snippet.setVisibility(GONE);
                }
                
        }

}

